/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PaginaPrincipal2.java
 *
 * Created on 01/05/2010, 02:48:48
 */

package judlawei.gui;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

/**
 *
 * @author Aislan M. de Lima
 */
public class PaginaPrincipal_v2 extends JFrame {

        
    private JPanel buscador;
    private JPanel logotipo;
    private JLabel rotNomeArq;
    private JButton botaoExtrair;
    private JPanel selecionadorTipo;
    private Visualizador2 v;
    
    
    public PaginaPrincipal_v2() {
        initComponents();
        construirLayout();
        initBotaoExtrair();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
   
    private void initComponents() {
        
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setResizable(false);
        logotipo = new Logotipo();
        buscador = new Buscador();
        rotNomeArq = new JLabel();
        botaoExtrair = new JButton();
        v = new Visualizador2();
        
        botaoExtrair.setText("Extrair");
        rotNomeArq.setText("Nome do Arquivo:");
        selecionadorTipo = new SelecionadorTipo();
        
    }
    
    
    private void construirLayout(){
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(buscador, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(logotipo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(selecionadorTipo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 205, Short.MAX_VALUE)
                        .addComponent(botaoExtrair)
                        .addGap(34, 34, 34))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(logotipo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(buscador, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(selecionadorTipo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoExtrair))
                .addGap(96, 96, 96))
        );

        pack();
    }

    
        
    private void initBotaoExtrair(){
        
        botaoExtrair.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                
                visualizarDoc();
                
            }
        });
    }
    
    private void visualizarDoc(){
        File f = ((Buscador) buscador).getArquivo();
        if ( f != null) {
            v.initDocOrig(f);
            v.setVisible(true);
        }
    }
    
    public static Border criaTitledBorder(String nome){
        return BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(""), 
                nome,TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                new Font("Tahoma",0,11), Color.blue);
    }
    
    
    /**
     * @param args the command line arguments
     */
     public static void main(String args[]) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 new PaginaPrincipal_v2().setVisible(true);
             }
         });
     }
    
}
